package se.topshelf.golftracker.core.service;

import se.topshelf.golftracker.core.domain.BaseEntity;

import java.util.List;

/**
 *
 */
public interface BaseService<T extends BaseEntity> {
    /**
     * @param id The id of the BaseEntity to fetch. Must be of type T (shortcut method)
     * @return The BaseEntity of type T
     */
    T get(String id);

    /**
     * @param baseEntityClass, the class type of the BaseEntity to get
     * @param id               The id of the BaseEntity
     * @return The entity if found, otherwise null
     */
    <S extends BaseEntity> S get(Class<S> baseEntityClass, String id);

    /**
     * Deletes the entity S, of type BaseEntity.
     *
     * @param entity to delete
     */
    <S extends BaseEntity> void delete(S entity);

    /**
     * Saves (persists for first time) or updates the entity S of type BaseEntity.
     *
     * @param entity to saveOrUpdate or update
     */

    <S extends BaseEntity> void saveOrUpdate(S entity);

    /**
     * @return All entities of type T currently stored
     */
    List<T> findAll();

    void clearSession();

    <S extends BaseEntity> S merge(S entity);

    /**
     * @param baseEntityClass, the class of which to return all entities
     * @return A List of all entities of type S
     */
    <S extends BaseEntity> List<S> findAll(Class<S> baseEntityClass);
}
